package com.example.demo.controller;

import com.example.demo.pojo.FidOutDto;
import com.example.demo.pojo.Rule;
import com.example.demo.pojo.em.EnumOKOrNG;
import com.example.demo.service.BRBService;
import com.example.demo.util.CommonUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Map;


@RestController
@RequestMapping("/stomach")
public class BRBController {

    @Autowired
    BRBService brbService;

    @ApiOperation(value = "获取诊断结果", notes = "获取诊断结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "DataIn", value = "[{FidIn:\"输入特征Id1\", Value:\"特征数值\"}, \n" +
                    "               {FidIn:\"输入特征Id2\", Value:\"特征数值\"}, \n" +
                    "               {FidIn:\"输入特征Id3\", Value:\"特征数值\"}", paramType = "query", required = true)
    })
    @RequestMapping("/diagnostic")
    public Map<String,Object> doDiagnostic(@RequestParam(value = "RecId") String RecId,
                                           @RequestParam(value = "DeptId") String DeptId,
                                           @RequestParam(value = "DataIn") String DataIn) {
        FidOutDto res = brbService.CalculateRes(RecId,DeptId,DataIn);
        return CommonUtil.setReturnMap(EnumOKOrNG.OK.getCode(), EnumOKOrNG.OK.getValue(),res);

    } 

    @ApiOperation(value = "更新规则")
    @RequestMapping("/updateRule")
    public String updateRule(@RequestParam(value = "newRule") String newRule){
        return brbService.updateService(newRule);
    }


    @ApiOperation(value = "删除规则")
    @RequestMapping("/deleteRule")
    public String deleteRule(@RequestParam(value = "id") int id){
        return brbService.deleteRule(id);
    }

    @ApiOperation(value = "显示规则")
    @RequestMapping("/showRules")
    public ArrayList<Rule> showRules(){
        return brbService.showRules();
    }

}
